package com.example.myweb.Controller.Auth;

import com.example.myweb.Common.ApiResponse;

import com.example.myweb.Dto.FeedItemDTO;
import com.example.myweb.Service.Auth.FeedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/feed")
public class FeedController {

    @Autowired
    private FeedService feedService;

    @GetMapping
    public ResponseEntity<ApiResponse<Page<FeedItemDTO>>> getFeed(
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "10") int size
    ) {
        // 注意：排序是在原生SQL中硬编码的，所以这里不需要再传Sort对象
        Pageable pageable = PageRequest.of(page, size);
        Page<FeedItemDTO> feedPage = feedService.getPublicFeed(pageable); // <-- 修改这里
        return ResponseEntity.ok(ApiResponse.success(feedPage, "信息流获取成功"));
    }
}